public class Demo3 {
    private static Object locker1 = new Object();
    private static Object locker2 = new Object();
    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
           synchronized (locker2){
               try {
                   System.out.println("获取到locker2");
                   Thread.sleep(1000);
               } catch (InterruptedException e) {
                   throw new RuntimeException(e);
               }
               synchronized (locker1){
                   System.out.println("获取到Locker1");
               }
           }
        });
        Thread t2 = new Thread(() -> {
            synchronized (locker1){
                try {
                    System.out.println("获取到locker1");
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                synchronized (locker2){
                    System.out.println("获取到Locker2");
                }
            }
        });
        t1.start();
        t2.start();
    }
}
